﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Castle.MicroKernel.Registration;
using Shape.Events;
using Shape.Mvp.Commands;
using Castle.Windsor;
using Shape.Mvp.Persistence.Conversations;
using Shape.Mvp.Persistence.Conversations.Hibernate;
using System.Configuration;
using NHibernate;
using Shape.Mvp.Persistence;

namespace Shape.Mvp.Ioc.Installers
{
	public class ServicesInstaller : IWindsorInstaller
	{

		public void  Install(Castle.Windsor.IWindsorContainer container, Castle.MicroKernel.SubSystems.Configuration.IConfigurationStore store)
		{
			container.Register(Component.For<IWindsorContainer>().Instance(container));

			container.Register(Classes.FromThisAssembly()
											  .BasedOn<IApplicationController>()
											  .WithServiceFromInterface()
											  .LifestyleSingleton());

			container.Register(Classes.FromThisAssembly()
											  .BasedOn<IEventAggregator>()
											  .WithServiceFromInterface()
											  .LifestyleSingleton());

			container.Register(Classes.FromThisAssembly()
											  .BasedOn<ICommandFactory>()
											  .WithServiceFromInterface()
											  .LifestyleSingleton());

			container.Register(Component.For<ISessionFactory>().UsingFactoryMethod<ISessionFactory>((c) => HibernateHelper.GetSessionFactory()));

			container.Register(Component.For<IConversationContainerAccessor>().ImplementedBy<HibernateConversationContainerAccessor>().LifestyleSingleton());
			container.Register(Component.For<IConversationFactory>().ImplementedBy<HibernateConversationFactory>().LifestyleSingleton());

		}
	}
}
